{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 用户筛选"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4ce7e1d01b5e4c7380f808c53a6e7f21",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(FloatProgress(value=1.0, bar_style='info', max=1.0), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from tqdm.notebook import tqdm\n",
    "file_dir = './data/train_data.csv'\n",
    "all_data_frame = pd.read_csv(file_dir)\n",
    "#selected_features = ['hour', 'gfrl','low_tp', 'high_tp', 'wind']\n",
    "\n",
    "########################################\n",
    "high_score_user = pd.read_csv('./data/filter_user.csv')\n",
    "high_score_user = high_score_user.iloc[:,0].tolist()\n",
    "########################################\n",
    "test = all_data_frame['ycsb']\n",
    "ycsb = []\n",
    "d = dict()\n",
    "for i,num in enumerate(test.tolist()):\n",
    "    if num not in d:\n",
    "        d[num] = 1\n",
    "    else:\n",
    "        d[num] = d[num] + 1\n",
    "for i,num in enumerate(d):\n",
    "    #{256: 70, 240: 48, 224: 17, 208: 2, 64: 2, 272: 2, 48: 2}\n",
    "    if (d[num] in [256, 240, 224, 272]) and num in high_score_user:\n",
    "        ycsb.append(num)\n",
    "\n",
    "count = dict()\n",
    "for i in ycsb:\n",
    "    count[str(i)] = 0\n",
    "\n",
    "train_data=[]\n",
    "for index, data in tqdm(all_data_frame.iterrows()):\n",
    "    if (data['ycsb'] in ycsb)and(count[str(data['ycsb'])]<224):\n",
    "        count[str(data['ycsb'])] = count[str(data['ycsb'])] + 1\n",
    "        train_data.append(data)\n",
    "data=pd.DataFrame(train_data)\n",
    "\n",
    "#data = data.drop('index', axis=1)\n",
    "\n",
    "data.to_csv('./data/train_data_lstm_.csv', encoding='utf_8_sig',index=None)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 用户单个文件输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c8314ead0bcc40efb6d90a341c204b59",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "HBox(children=(FloatProgress(value=1.0, bar_style='info', max=1.0), HTML(value='')))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from tqdm.notebook import tqdm\n",
    "\n",
    "file_dir = './data/train_data_lstm.csv'\n",
    "all_data_frame = pd.read_csv(file_dir)\n",
    "test = all_data_frame['ycsb']\n",
    "ycsb = list(set(np.array(test)))\n",
    "count = dict()\n",
    "\n",
    "for i in ycsb:\n",
    "    count[str(i)] = 0\n",
    "train_data=[]\n",
    "\n",
    "for index, data in tqdm(all_data_frame.iterrows()):\n",
    "    if count[str(data['ycsb'])]<224:\n",
    "        count[str(data['ycsb'])] = count[str(data['ycsb'])] + 1\n",
    "        train_data.append(data)\n",
    "        if count[str(data['ycsb'])]==224:\n",
    "            user_data=pd.DataFrame(train_data)\n",
    "            path = './data/user_data/'+data['ycsb']+'.csv'\n",
    "            user_data.to_csv(path, encoding='utf_8_sig',index=None)\n",
    "            train_data=[]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
